package com.wxx.shares.changes;

import com.wxx.push.WeChatPush;
import com.wxx.util.CrawlerUtil;
import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.processor.PageProcessor;

import java.util.ArrayList;
import java.util.List;

/**
 * 获取近5个月股票的涨跌幅
 */
public class SharesChangeProcess implements PageProcessor {

    SharesChangeDownloader downloader = new SharesChangeDownloader();

    public void process(Page page) {
       // 无需在这处理，在下载器里已经处理
    }

    public Site getSite() {
        return Site.me().setRetryTimes(10).setSleepTime(100);
    }

    public void start() {
        List<String> taskList = new ArrayList<>();
        taskList.add("http://data.eastmoney.com/zjlx/002217.html");   // 合力泰
        taskList.add("http://data.eastmoney.com/zjlx/000725.html");   // 京东方A
        taskList.add("http://data.eastmoney.com/zjlx/000651.html");   // 格力电器
        taskList.add("http://data.eastmoney.com/zjlx/zs000001.html"); // 上证指数

        Spider spider = CrawlerUtil.genSpider(this, downloader);
        for (String url: taskList) {
            spider.addUrl(url);
        }
        spider.run();

        System.out.println("结束：" + downloader.dataList.toString());
        WeChatPush.pushText("分析完成");
    }

    public static void main(String[] args) {
        new SharesChangeProcess().start();
    }

}